import axios from "axios";

axios.defaults.timeout = 3000;

function http(url = "", type = "get", data = {}) {
  let p;
  return new Promise(function (resolve, reject) {
    if (type === "get") {
      p = axios.get(url, { params: data });
    } else if (type === "post") {
      p = axios.post(url, data);
    }
    p.then((res) => {
      resolve(res);
    }).catch((error) => {
      reject(error);
    });
  });
}

export default http;
